<?php
//根据身份证号获取生日
function get_info_by_idnum($id_num){
    $year=substr($id_num,6,4);
    $month=substr($id_num,10,2);
    $day=substr($id_num,12,2);
    $sex=substr($id_num,16,1);
    $user['age']=date('Y')-$year;
    //$user['birthday']=$year.'-'.$month.'-'.$day;
    $user['sex']=$sex%2==0?2:1;
    return $user;
}
//判断按钮权限
function check_auth($path){
    if($_SESSION['admin']['id']==1) return true;//超级管理员跳过判断
    if(empty($_SESSION['admin']['menu_ids'])) return false;
    $path=trim($path,'/');
    $node_id=db()->getOne('select id from x_menu where path="'.$path.'"');
    if(!$node_id) return false;
    if(strpos(','.$_SESSION['admin']['menu_ids'].',',','.$node_id.',')!==false){
        return true;
    }
    else return false;
}

//获取后台菜单树
function getTree($data,$id){
    $tree=array();
    foreach($data as $k => $v){
        if($v['pid']==$id){
            $v['children'] = getTree($data,$v['id']);
            $tree[] = $v;
        }
    }
    return $tree;
}
 /*
 * :  写日志
 * method:    操作(1-插入，2-更新)      //枚举类型数据
 * logs: json_encode($_POST) 多个SQL语句push到$_POST中
 * remark: 操作描述
 *
 * ***********
 * $mid : 模块id;
 * $act : 前台或后台
 * $infoid : 操作信息所影响到的记录id
 */
function insertlogs($method,$remark,$logs=array(),$infoids){
    $ip = get_client_ip(0,true);        //获取ip
    $path  = M_NAME.'/'.C_NAME.'/'.A_NAME;       //操作方法路径;
    $time = time();                              // 日志存入事件戳
    $uname = $_SESSION['client']['name'];
    $logs = json_encode($logs);
    $array = array('operation_id'=>$_SESSION['client']['id'],'info'=>$logs,'infoid'=>$infoids,'time'=>$time,'ip'=>$ip,'type'=>$method,'beizhu'=>$remark,'operation_name'=>$uname,'is_back'=>'jiaxiao_admin','modules'=>C_NAME,'path'=>$path,'school_id'=>$_SESSION['client']['jx_id']);
    $rs = db()->insert('x_log',$array);
    return $rs;
}
